package cn.sc.summer.mybatis.config;

import cn.sc.summer.mybatis.config.interceptor.DataSourceInterceptor;
import cn.sc.summer.mybatis.config.interceptor.MybatisLogSqlInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * 类名：手动设置bean
 *
 * @author a-xin
 * @date 2023/11/23 16:51
 */
@Slf4j
@Configuration
public class ParamConfig implements ApplicationContextAware {

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Environment environment = applicationContext.getEnvironment();
        Long sqlTime = environment.getProperty("sql.time", Long.class, 500L);
        MybatisLogSqlInterceptor.init(sqlTime);
        Boolean enable = environment.getProperty("mybatis-plus.read-write.enable", Boolean.class, Boolean.FALSE);
        DataSourceInterceptor.init(enable);
        log.info("==> Start initialization params！");
    }

}
